package com.tarena.lbs.business.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.business.pojo.param.StoreParam;
import com.tarena.lbs.business.pojo.param.UserLocationParam;
import com.tarena.lbs.business.pojo.query.AreaStoreQuery;
import com.tarena.lbs.business.pojo.query.StoreQuery;
import com.tarena.lbs.business.pojo.vo.StoreVO;
import com.tarena.lbs.business.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "店铺相关功能接口")
@RestController
@Slf4j
public class StoreController {
    @Autowired
    StoreService storeService;

    @ApiOperation(value = "查询店铺列表")
    @PostMapping("/admin/basic/store/getAll")
    public Result<PageResult<StoreVO>> pageList(@RequestBody StoreQuery query)
        throws BusinessException {
        log.info("查询店铺列表参数:{}", query);
        PageResult<StoreVO> pageResult = storeService.pageList(query);
        return new Result("0","success",pageResult);
    }

    /**
     * 新增店铺
     * @param param
     * @return
     * @throws BusinessException
     */
    @ApiOperation(value = "新增店铺")
    @PostMapping("/admin/basic/store/add")
    public Result<Void> save(@RequestBody StoreParam param)
        throws BusinessException {
        log.info("新增店铺参数：{}", param);
        storeService.save(param);
        return Result.success();
    }

    //查询 属于当前登录用户 所属商家 和满足区域条件的店铺列表
    @ApiOperation(value = "查询区域下的店铺列表")
    @PostMapping("/admin/basic/store/getStoreByCity")
    public Result<PageResult<StoreVO>> getStoreByCity(@RequestBody AreaStoreQuery query)
        throws BusinessException {
        return null;
    }

    @ApiOperation(value = "启用店铺")
    @PostMapping("/admin/basic/store/enable/{id}")
    public Result<Void> enable(@PathVariable Integer id)
        throws BusinessException {
        log.info("停用/启用店铺参数：{}", id);
        storeService.enable(id);
        return Result.success();
    }
    @ApiOperation(value = "停用店铺")
    @PostMapping("/admin/basic/store/disable/{id}")
    public Result<Void> disable(@PathVariable Integer id)
            throws BusinessException {
        log.info("停用店铺参数：{}", id);
        storeService.disable(id);
        return Result.success();
    }

    @ApiOperation(value = "删除店铺")
    @PostMapping("/admin/basic/store/delete/{id}")
    public Result<Void> delete(@PathVariable Integer id)
            throws BusinessException {
        log.info("删除店铺参数：{}", id);
        storeService.delete(id);
        return Result.success();
    }

    // 店铺详情
    @ApiOperation(value = "店铺详情")
    @GetMapping("/admin/basic/store/{id}")
    public Result<StoreVO> detail(@PathVariable Integer id)
        throws BusinessException {
        log.info("店铺详情参数：{}", id);
        StoreVO storeVO = storeService.detail(id);
        return new Result("0","success",storeVO);
    }

    //手机小程序定位上报
    @ApiOperation(value = "手机小程序定位上报")
    @PostMapping("/basic/store/location")
    public Result<Void> location(@RequestBody UserLocationParam param)
        throws BusinessException{
        return Result.success();
    }

    @ApiOperation(value = "二维码列表")
    @GetMapping("/admin/basic/chain/getAll")
    public Result getAll()
        throws BusinessException{
        return null;
    }

    @ApiOperation(value = "编辑店铺")
    @PostMapping("/admin/basic/store/update")
    public Result<Void> update(@RequestBody StoreParam param)
            throws BusinessException {
        log.info("编辑店铺参数：{}", param);
        storeService.updateStore(param);
        return Result.success();
    }


}
